home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Examples / TinyTerm / TinyTermWindow.m < prev   
Encoding:
Text File  |  1995-04-12  |  1.2 KB  |  62 lines

  1. // Copyright 1995 Matt Brandt.
  2. // Use is governed by the MiscKit license
  3.  
  4. #import "TinyTermWindow.h"
  5.  
  6. @implementation TinyTermWindow
  7.  
  8. - initContent: (const NXRect *)contentRect
  9.     style: (int)aStyle
  10.     backing: (int)backingType
  11.     buttonMask: (int)mask
  12.     defer: (BOOL)flag
  13. {
  14.     self = [super initContent: contentRect style: aStyle
  15.         backing: backingType buttonMask: mask defer: flag];
  16.     port = [[MiscSerialPort alloc] init];
  17.     [port setDeviceName: "/dev/cufa"];
  18.     [port setBaudByName: "9600"];
  19.     [port setDelegate: self];
  20.     if( ![port connect] )
  21.         [self setTitle: "Could not open /dev/cufa"];
  22.     return self;
  23. }
  24.  
  25. - makeFirstResponder: aResponder
  26. {
  27.     return nil;
  28. }
  29.  
  30. - keyDown: (NXEvent *)theEvent
  31. {
  32.     char    buf[4];
  33.     
  34.     buf[0] = theEvent->data.key.charCode;
  35.     [port transmitChars: buf length: 1];
  36.     return self;
  37. }
  38.  
  39. - receiveChars: (char *)buffer length: (int)length
  40. {
  41.     int        i, endpos;
  42.     
  43.     for( i = 0; i < length; ++i )
  44.         if( buffer[i] == '\r' )
  45.             buffer[i] = ' ';
  46.     endpos = [myText textLength];
  47.     [myText setSel: endpos : endpos];
  48.     [myText replaceSel: buffer length: length];
  49.     endpos = [myText textLength];
  50.     [myText setSel: endpos : endpos];
  51.     [myText scrollSelToVisible];
  52.     return self;
  53. }
  54.  
  55. - hangup
  56. {
  57.     return self;
  58. }
  59.  
  60.  
  61. @end
  62.